/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jee.forum.controller;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import jee.forum.entities.Forum;
import org.apache.log4j.Logger;

/**
 *
 * @author Tobi
 */
@Stateless
public class ForumController {

    @PersistenceContext
    private EntityManager em;

    private Logger log = Logger.getLogger(ForumController.class);
    
    public void createForum(String name, String description) throws Exception{
        log.info("Create new Forum: "+name);

         Forum forum = new Forum(name, description);
         em.persist(forum);
    }

    public Forum getForumById(int id){
            Forum forum = em.find(Forum.class, id);
            return forum;
    }

    public List getForums(){

        List forums = em.createQuery("SELECT f from Forum f").getResultList();
        return forums;  
    }
}
